package insight.google.game.era.data;

import java.util.HashMap;

import javax.jdo.PersistenceManager;

import sun.text.normalizer.Trie.DataManipulate;

public abstract class AppDataManager {

	protected DataStoreManager dataStoreMgr = null;
	protected TransactionHandler txHandler;
	protected PersistenceManager pManager;
	protected  boolean isDetachable = false;
	public void initialize(){
		dataStoreMgr = DataStoreManager.getInstance();
		if(this.txHandler == null){
			pManager = this.dataStoreMgr.getPersistentManager();
		}else{
			pManager = this.txHandler.getPersistenceManager();
		}
	}
	
	public boolean addToDataStore(Object o) {
		try {
			dataStoreMgr.save(o, pManager,isDetachable);
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return false;
	}
	
	public boolean removeFromDataStore(Object o){
		if(o != null){
			this.dataStoreMgr.delete(o, pManager);
		}
		return true;
	}
	public abstract Object findAll();
	
	public void commit(){
		if(txHandler != null){
			txHandler.commit();
		}
	}
	
	
	public TransactionHandler getTransactionHandler(){
		return this.txHandler;
	}
	
	public void close(){
		if(txHandler != null){
			this.txHandler.close();
		}
	}

	public boolean isDetachable() {
		return isDetachable;
	}

	public void setDetached(boolean isDetachable) {
		this.isDetachable = isDetachable;
	}
	
	
}
